package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.laws.LindiLawsQueryVO;
import com.minimalist.common.entity.lindi.vo.laws.LindiLawsVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiLawsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_政策法规管理")
@RequestMapping("/lindi/laws")
public class LindiLawsController{

    @Autowired
    private LindiLawsService service;

    @PostMapping("/addLaws")
    @Operation(summary = "添加政策法规")
    public R<?> addLaws(@RequestBody @Validated(Add.class) LindiLawsVO lawsVO){
        service.addLaws(lawsVO);
        return R.ok();
    }

    @DeleteMapping("/deleteLawsByLawsId")
    @Operation(summary = "删除政策法规 -> 根据政策法规ID删除")
    public R<?> deleteLawsByLawsId(
            @RequestParam("lawsId")
            @NotNull(message = "政策法规ID不能为空")
            @Parameter(name = "lawsId", required = true, description = "政策法规ID")
            Long lawsId){
        service.deleteLawsByLawsId(lawsId);
        return R.ok();
    }

    @PutMapping("/updateLawsByLawsId")
    @Operation(summary = "修改政策法规")
    public R<?> updateLawsByLawsId(
            @RequestBody @Validated(Update.class) LindiLawsVO lawsVO){
        service.updateLawsByLawsId(lawsVO);
        return R.ok();
    }

    @GetMapping("/getPageLawsList")
    @Operation(summary = "查询政策法规列表(分页)")
    public R<PageResp<LindiLawsVO>> getPageLawsList(@RequestBody LindiLawsQueryVO queryVO){
        return R.ok(service.getPageLawsList(queryVO));
    }

    @GetMapping("/getLawsByLawsId/{lawsId}")
    @Operation(summary = "根据政策法规ID查询政策法规")
    public R<LindiLawsVO> getLawsByLawsId(
            @PathVariable(value = "lawsId")
            @NotNull(message = "政策法规ID不能为空")
            @Parameter(name = "lawsId", description = "政策法规ID", required = true)
            Long lawsId){
        return R.ok(service.getLawsByLawsId(lawsId));
    }
}